package main

import (
	_ "ones-objects/datas-api/init"
	"ones-objects/config"
	"net/http"
	"time"
	"ones-objects/datas-api/objects"
	"ones-objects/datas-api/heartbeat"
	"ones-objects/datas-api/locate"
)

func main()  {
	//发布datas-api的心跳给objects-api，确保服务的连通
	go heartbeat.StartHeartBeat()
	//监听api发送的对象存在的消息，同时判断对内容进行确认
	go locate.StartLocate()

	//定义http的服务端代码程序，路由策略
	mux := http.DefaultServeMux
	mux.Handle(config.OBJECTS_PATH, http.HandlerFunc(objects.Handler))
	//http的服务配置
	server := &http.Server{
		Addr: config.GetString(config.APP_SERVER_PORT),
		ReadTimeout: time.Duration(config.GetInt64Def(config.APP_SERVER_READTIMEOUT, 100)) * time.Millisecond,
		WriteTimeout: time.Duration(config.GetInt64Def(config.APP_SERVER_WRITETIMEOUT, 100)) * time.Millisecond,
		Handler:mux,
	}
	server.ListenAndServe()
}
